package org.auf.controllers;

import java.io.IOException;

import org.auf.core.Controller;
import org.auf.core.UIDGenerator;
import org.auf.model.dao.ITestDAO;
import org.auf.model.jdbc.TestDAOJDBC;
import org.auf.to.Test;
import org.auf.to.User;

public class NewUserController extends Controller {

	@Override
	public void show() {
		//TODO: Pendiente de revision
		User temp = new User();
		String name, password, mail, geek, score, id, idTest;
		boolean isGeek=false;
		name = (String) request.getAttribute("name");
		password = (String) request.getAttribute("password");
		mail = (String) request.getAttribute("mail");
		geek = (String) request.getAttribute("geek");
		score = (String) request.getAttribute("score");
		id = UIDGenerator.getInstance().getKey();		
		
		temp.setId(id);
		temp.setMail(mail);
		temp.setName(name);
		temp.setPassword(password);
		temp.setGeek(geek == "geek");
		temp.setScore(Integer.valueOf(score));
		
		request.setAttribute("userTemp", temp);
		
		Test exam = new Test();
		ITestDAO testdao = new TestDAOJDBC();
		exam = testdao.selectRamdomTest();
		idTest = exam.getId();
		if (temp.getGeek()) { // si es geek, debe hacer un test
			try {
				response.sendRedirect("?action=showtest&=id" + idTest);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} else {
			try {
				response.sendRedirect("?action=main&=id" + id);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
